#include <cassert>
#include "../source/util.hh"
#include "../source/info.hh"

void test_file()
{
    std::string res;
    cloud::util::file("test.pk").pack("test.upk");
    cloud::util::file("test.upk").unpack("test.pk2");
    cloud::util::file("test.pk").unpack(&res);
}

void test_json()
{
    float score[] = {88.3, 99.1, 79.6};

    cloud::util::json js;
    js.set("姓名", "小明");
    js.set("性别", "男");

    // std::string res = cloud::util::json::serialize();
    // std::cout << res << std::endl;
    //
    // Json::Value root2 = cloud::util::json::deserialize(res);
    // std::cout << "姓名  " << root["姓名"] << std::endl;
    // std::cout << "性别  " << root["性别"] << std::endl;
    // std::cout << "成绩1 " << root["成绩"][0] << std::endl;
    // std::cout << "成绩2 " << root["成绩"][1] << std::endl;
    // std::cout << "成绩3 " << root["成绩"][2] << std::endl;
}

void test_path()
{
    std::cout << cloud::util::path::fpath2bpath("test.cc") << std::endl;
    std::cout << cloud::util::path::fpath2ppath("test.cc") << std::endl;
    std::cout << cloud::util::path::fpath2dlurl("test.cc") << std::endl;
    std::cout << cloud::util::path::bpath2fpath("back_dir/test.cc") << std::endl;
    std::cout << cloud::util::path::bpath2ppath("back_dir/test.cc") << std::endl;
    std::cout << cloud::util::path::bpath2dlurl("back_dir/test.cc") << std::endl;
    std::cout << cloud::util::path::ppath2fpath("pack_dir/test.cc.snp") << std::endl;
    std::cout << cloud::util::path::ppath2bpath("pack_dir/test.cc.snp") << std::endl;
    std::cout << cloud::util::path::ppath2dlurl("pack_dir/test.cc.snp") << std::endl;
    std::cout << cloud::util::path::dlurl2fpath("/download/test.cc") << std::endl;
    std::cout << cloud::util::path::dlurl2bpath("/download/test.cc") << std::endl;
    std::cout << cloud::util::path::dlurl2ppath("/download/test.cc") << std::endl;
}

void test_sem()
{
    cloud::util::semaphore sem(0);

    sem.wait();
    std::cout << "wait pass" << std::endl;
}

#define TEST \
                3
int main()
{
    switch (TEST)
    {
    case 1: test_file(); break;
    case 2: test_json(); break;
    case 3: test_path(); break;
    case 4: test_sem(); break;
    default: assert(false);
    }
    return 0;
}
